<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class hopdong_db 
	{
		public function Them($MaHopDong, $MaGiaoVien, $MaLopHoc, $MaVaiTro, $LuongMoiTiet, $TuNgay, $DenNgay, $NgayKy, $PIN)
		{
			$sql = "INSERT INTO `tbl_hopdong`(`MaHopDong`, `MaGiaoVien`, `MaLopHoc`, `MaVaiTro`, `LuongMoiTiet`, `TuNgay`, `DenNgay`, `NgayKy`, `PIN`)
					VALUES ('$MaHopDong', '$MaGiaoVien', '$MaLopHoc', '$MaVaiTro', '$LuongMoiTiet', '$TuNgay', '$DenNgay', '$NgayKy', '$PIN')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaHopDong)
		{
			$sql = "DELETE FROM `tbl_hopdong` WHERE `MaHopDong` = '$MaHopDong'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaHopDong, $MaGiaoVien, $MaLopHoc, $MaVaiTro, $LuongMoiTiet, $TuNgay, $DenNgay, $NgayKy, $PIN)
		{
			$sql = "UPDATE `tbl_hopdong`
					SET `MaGiaoVien` = '$MaGiaoVien', `MaLopHoc` = '$MaLopHoc', `MaVaiTro` = '$MaVaiTro', `LuongMoiTiet` = '$LuongMoiTiet', `TuNgay` = '$TuNgay', `DenNgay` = '$DenNgay', `NgayKy` = '$NgayKy', `PIN` = '$PIN'
					WHERE `MaHopDong` = '$MaHopDong'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaHopDong, $MaGiaoVien, $MaLopHoc, $MaVaiTro, $LuongMoiTiet, $TuNgay, $DenNgay, $NgayKy, $PIN)
		{
			$sql = "SELECT * FROM `tbl_hopdong` WHERE 1  ";
			if($MaHopDong != -1)
				$sql .= " AND `MaHopDong` = '$MaHopDong' ";

			if($MaGiaoVien != "")
				$sql .= " AND `MaGiaoVien` = '$MaGiaoVien' ";

			if($MaLopHoc != "")
				$sql .= " AND `MaLopHoc` = '$MaLopHoc' ";

			if($MaVaiTro != "")
				$sql .= " AND `MaVaiTro` = '$MaVaiTro' ";

			if($LuongMoiTiet != -1)
				$sql .= " AND `LuongMoiTiet` = '$LuongMoiTiet' ";

			if($TuNgay != "0000-00-00")
				$sql .= " AND `TuNgay` = '$TuNgay' ";

			if($DenNgay != "0000-00-00")
				$sql .= " AND `DenNgay` = '$DenNgay' ";

			if($NgayKy != "0000-00-00")
				$sql .= " AND `NgayKy` = '$NgayKy' ";

			if($PIN != "")
				$sql .= " AND `PIN` = '$PIN' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

